package cn.net.withub.dataCollector.common.editor;

import org.springframework.util.StringUtils;

import java.beans.PropertyEditorSupport;

public class BooleanEditor extends PropertyEditorSupport {
	@Override
	public void setAsText(String text) throws IllegalArgumentException {

		if (!StringUtils.hasText(text)) {
			setValue(null);
		} else {
			if(text.trim().equals("true")){
				setValue(true);
			}else{
				setValue(false);
			}
			
		}
	}

	@Override
	public String getAsText() {

		return getValue().toString();
	}
}
